package edu.cuit.zhuyimeng.flight.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import edu.cuit.zhuyimeng.flight.controller.dto.CreateFlightDTO;
import edu.cuit.zhuyimeng.flight.service.IFlightDispatchService;
import edu.cuit.zhuyimeng.flight.service.IFlightManagerService;
import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.MonthDay;

/**
 * 管理员用控制器
 */
@RestController
//@SaCheckPermission("flight:admin")
@RequestMapping("/admin")
@Tag(name = "管理员航班管理")
@Validated
@RequiredArgsConstructor
public class AdminController {

    private final IFlightManagerService flightManagerService;
    private final IFlightDispatchService flightDispatchService;

    /**
     * 创建航班
     */
    @Operation(summary = "创建航班",security = @SecurityRequirement(name = "Authorization"))
    @PutMapping("/flight")
    public CommonResult<Void> createFlight(@RequestBody @Valid CreateFlightDTO flight) {
        flightManagerService.createFlight(flight);
        return CommonResult.success();
    }

    /**
     * 起飞指令
     */
    @Operation( summary = "起飞指令",security = @SecurityRequirement(name = "Authorization"))
    @PostMapping("/takeoff")
    public CommonResult<Void> takeoff(@RequestParam("id") @NotNull Long id) {
        flightDispatchService.takeoff(id);
        return CommonResult.success();
    }

    /**
     * 降落指令
     */
    @Operation(summary = "降落指令",security = @SecurityRequirement(name = "Authorization"))
    @PostMapping("/land")
    public CommonResult<Void> landing(@RequestParam("id") @NotNull Long id) {
        flightDispatchService.landing(id);
        return CommonResult.success();
    }

    /**
     * 删除航班
     */
    @Operation(summary = "删除航班",security = @SecurityRequirement(name = "Authorization"))
    @DeleteMapping("/flight")
    public CommonResult<Void> removeFlight(@RequestParam("id") @NotNull Long id) {
        flightManagerService.adminRemoveFlight(id);
        return CommonResult.success();
    }

    /**
     * 刷新航班缓存
     */
    @Operation(summary = "刷新航班缓存",security = @SecurityRequirement(name = "Authorization"))
    @PostMapping("/cache")
    public CommonResult<Void> refreshFlightCache(@RequestParam("id") @NotNull Long id) {
        flightManagerService.refreshFlightCache(id);
        return CommonResult.success();
    }

}
